package cn.Service.Impl;

import cn.Dao.ConsumerBasicInfoDao;
import cn.Dao.ConsumptionRecordDao;
import cn.Dao.MaScanPointDao;
import cn.Dao.PlatinumbagRedEnvelopeRepository;
import cn.Entity.ConsumerBasicInfo;
import cn.Entity.ConsumptionRecord;
import cn.Entity.Employee;
import cn.Entity.MaScanPoint;
import cn.MetaData.Annotation.ChooseDataSource;
import cn.Service.QueryDataByMutilDataSource;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Service
@Slf4j
public class QueryDataByMutilDataSourceImpl implements QueryDataByMutilDataSource {

    @Autowired
    private ConsumerBasicInfoDao consumerBasicInfoDao;
    @Autowired
    private ConsumptionRecordDao consumptionRecordDao;
    @Autowired
    private MaScanPointDao maScanPointDao;
    @Autowired
    private PlatinumbagRedEnvelopeRepository platinumbagRedEnvelopeRepository;

    /**
     * 默认数据源
     * @return
     */

    @ChooseDataSource()
    public List listAllConsumptionRecord(){
        List<ConsumptionRecord> consumptionRecordList = consumptionRecordDao.selectList(null);
        return consumptionRecordList;
    }

//    @Override
    @ChooseDataSource(dataSourceName = "MinorDatasource")
    public List listAllConsumerBasicInfo() {
        return consumerBasicInfoDao.selectList(null);
    }

//    @Override
    @ChooseDataSource(dataSourceName = "ThirdDatasource")
    public List listAllMaScanPoint() {
        return maScanPointDao.selectList(null);
    }

//    @Override
@ChooseDataSource(dataSourceName = "ThirdDatasource")
public List listAllMaScanPointInInnerCodes( String innerCodes) {

        QueryWrapper<MaScanPoint> maScanPointWrapper = new QueryWrapper<>();
        maScanPointWrapper.inSql("innerCode", innerCodes);

        return maScanPointDao.selectList(maScanPointWrapper);
    }


    @Override
    @ChooseDataSource()
    public List listAllPlatinumBagEnvelopeRecord() {
        return platinumbagRedEnvelopeRepository.selectList(null);
    }


}
